﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace DCTLib.Common
{
    public class AppRequestInfo
    {
        private static HttpContext Context
        {
            get
            {
                return HttpContext.Current;
            }
        }

        private static string GetString(string key)
        {
            return Context.Request[key];
        }

        private static int GetInt(string key)
        {
            try
            {
                return (Context.Request[key] == null) ? -1 : Convert.ToInt32(Context.Request[key]);
            }
            catch (FormatException)
            {
                return -1;
            }
        }

        private static bool IsExist(string key)
        {
            return (Context.Request[key] != null);
        }

        public static int ID
        {
            get
            {
                return GetInt(AppQueryKeys.ID);
            }
        }

        /// <summary>
        ///  Return current string ID request parameter.
        /// </summary>
        public static string IDStr
        {
            get
            {
                return GetString(AppQueryKeys.ID);
            }
        }

        /// <summary>
        /// Return current integer subID request parameter.
        /// </summary>
        public static int SubID
        {
            get
            {
                return GetInt(AppQueryKeys.SUBID);
            }
        }

        public static string SubIDStr
        {
            get
            {
                return GetString(AppQueryKeys.SUBID);
            }
        }

        public static ActionType Action
        {
            get
            {
                if (!IsExist(AppQueryKeys.ACTION_TYPE))
                {
                    return ActionType.Unknown;
                }

                switch (Context.Request[AppQueryKeys.ACTION_TYPE].ToLower())
                {
                    case "add":
                        return ActionType.Add;
                    case "update":
                        return ActionType.Update;
                    case "view":
                        return ActionType.View;
                    default:
                        return ActionType.Unknown;
                }
            }
        }

        public static string ADMIN_ID
        {
            get
            {
                return (GetString(AppQueryKeys.ADMIN_ID));
            }
        }

        public static string ReturnURL
        {
            get
            {
                return GetString(AppQueryKeys.RETURN_URL);
            }
        }

        public static string Value
        {
            get
            {
                return GetString(AppQueryKeys.VALUE);
            }
        }

        public static string Query
        {
            get
            {
                return GetString(AppQueryKeys.QUERY);
            }
        }



    }
}
